#ifndef __LUNA_SoundManager_h__
#define __LUNA_SoundManager_h__

#include "LUNA_Common.h"
#include "LUNA_VorbisSystem.h"

#include "al.h"
#include "alc.h"
		
namespace LUNA
{
	class LunaExport SoundManager
	{		
		typedef std::map<std::string,ISoundFactory*> SoundFactoryMap;
		typedef std::vector<ISound*> SoundVector;

	public:
		SoundManager();
		~SoundManager();

		void update();

		void initialize();
		void shutdown();

		ISound *createSound( const std::string &filename, 
			const std::string &soundType );
		void destroySound( ISound *sound );

		void registerSoundFactory( ISoundFactory *factory );
		void unregisterSoundFactory( ISoundFactory *factory );
		bool isSoundFactoryAvailable( const std::string &name );
		StringList listAvailableSoundFactories() const;

		VorbisSystem &getVorbisSystem();

		float getVolume() const;
		void setVolume( float volume );

	private:
		ISoundFactory *getFactory( const std::string &name );

		void initializeOpenAL();
		void shutdownOpenAL();
		bool isOpenALInitialized() const;

		void initializeVorbis();
		void shutdownVorbis();
		bool isVorbisInitialized() const;

	private:
		bool mOpenALInitialized;
		bool mVorbisInitialized;
		
		VorbisSystem mVorbis;

		SoundFactoryMap mFactories;
		SoundVector mSounds;

		float mVolume;

		ALCcontext *mContext;
		ALCdevice *mDevice;
	};
}

#endif